﻿#region Copyright (c) 2008 plexBB Team
/*  Copyright (c) 2008 plexBB Team
 *  
 *  This file is free software: you may copy, redistribute and/or modify it  
 *  under the terms of the GNU General Public License as published by the  
 *  Free Software Foundation, either version 2 of the License, or (at your  
 *  option) any later version.  
 *  
 *  This file is distributed in the hope that it will be useful, but  
 *  WITHOUT ANY WARRANTY; without even the implied warranty of  
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU  
 *  General Public License for more details.  
 *  
 *  You should have received a copy of the GNU General Public License  
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 */
#endregion

using System;
using System.Web.UI;
using PlexBB.Controls;

namespace PlexBB
{
    /// <summary>
    /// Base class for root templates.
    /// </summary>
    public abstract class RootTemplate : ForumControl
    {
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            IAttributeAccessor root = GetRootControl();
            if (root != null)
            {
                if (Lang["DIRECTION"] == "rtl")
                {
                    root.AppendAttribute("class", "rtl");
                }

                root.SetAttribute("dir", Lang["DIRECTION"]);
                root.SetAttribute("lang", Lang["USER_LANG"]);
            }

            LiteralControl flowsStyle = new LiteralControl(string.Format(@"<style type='text/css'>.flowBegin{{float:{0};}}.flowEnd{{float:{1};}}</style>",
                Lang["DIRECTION"] == "ltr" ? "left" : "right",
                Lang["DIRECTION"] == "ltr" ? "right" : "left"));

            Page.Header.Controls.Add(flowsStyle);
        }

        /// <summary>
        /// Override and return root control that needs to have root forum styles to be applied (dir, lang, etc.)
        /// </summary>
        protected abstract IAttributeAccessor GetRootControl();
    }
}
